<?php
/**
 * 搜索引擎模型 - 核心应用
 * @author jason <yangjs17@yeah.net> 
 * @version TS3.0
 */
class TestDataModel extends Model {

	protected $tableName = 'test_data';
	protected	$fields	= array(
		0=>'test_id',
		1=>'stu_id',
		2=>'year',
		3=>'date',
		4=>'test_number',
		5=>'modes_transportation',
		6=>'balanceBeam',
		7=>'continuousJump',
		8=>'tennis_throw',
		9=>'standing_long_jump',
		10=>'flexion',
		11=>'reentry_run',
		12=>'vision_right',
		13=>'vision_left',
		14=>'skinfold_abdomen',
		15=>'skinfold_shoulder_armor',
		16=>'skinfold_upper_arm',
		17=>'heart_rate',
		18=>'sit_height',
		19=>'weight',
		20=>'height',
		21=>'chest',
		22=>'is_update',
		23=>'is_report',
		24=>'is_del',
		25=>'admin_id',
		26=>'ctime',
		27=>'status',
		28=>'class_id',
		29=>'class_type',
	);
	//通过测试id查询测试数据的完成度
	public function getResutlByTestId($test_id) {	
		$sum=0;
		$test_project=M("test_project")->field("english_name")->findALL();
		foreach ($test_project as $key => $value) {
			$data=$this->where("test_id=".$test_id)->field($value["english_name"])->find();
			if($data[$value["english_name"]]>0){
				$sum++;
			}
		}
		return 100/count($test_project)*$sum."%";
	}
	//通过班级id,测试年份和测试次数查询测试该班人数
	public function getTestNumber($class_id,$year,$number) {	
		$sum=0;
		$student=M("student")->where("class_id=".$class_id)->field("stu_id")->findALL();
		foreach ($student as $key => $value) {
			$where=array(
				'is_del'=>0,
				'is_report'=>1,
				'stu_id'=>$value["stu_id"],
				'year'=>$year,
				'test_number'=>$number
			);
			$test_data=$this->where($where)->find();
			if($test_data){
				$sum++;
			}
		}
		return $sum;
	}
	public function getAdviceImage($type){
		$data="";
		$type=explode(",", $type);
		foreach ($type as $key => $value) {
			if($key+1==count($type)){
				$data.=$this->getOneHealthAdvice($value);
			}else{
				$data.=$this->getOneHealthAdvice($value).",";
			}
		}
		return $data;
	}
	public function getOneHealthAdvice($type){
		$advice=M("health_advice")->where("is_del=0 and advice_type=".$type)->field("advice_id")->findAll();
		$advice=getSubByKey($advice,'advice_id');
        $data=array_rand($advice);
        return $advice[$data];
	}
}